Missing Apache Aliases under FastCGI

When setting directory aliases under an Apache virtual host, PHP running as Apache module will automatically recognize the aliases and convert to target directories, for example:

Apache: Alias /images D:\www\website_content\images

PHP: file_put_contents('/images/'.$img_filename, $img);

However, when PHP is running under Fast-CGI, as on Windows or IBMi, PHP path functions, such as dir ('/images'), will fail to locate target path references from Apache aliases, thus breaking your code flow.

To circumvent this outcome, we recommend using portable practices such as referencing __FILE__ and __DIR__. If you must set directory aliases, use Environment variables instead.

In addition to the aliases which will match Linux running Zend Server PHP Apache module, you can add ENV vars, for example:

Apache: SetEnv DIR_IMAGES D:\www\website_content\images

Then check if they are available from PHP, and use their values as target directories in your application code:

PHP: $images_dir = getenv('DIR_IMAGES');

Note:

This solution is also applicable to Zend Server running with nginx under PHP-FPM pool.